package com.itbbfx.service.system.impl;

import com.itbbfx.entity.Menu;
import com.itbbfx.mapper.MenuMapper;
import com.itbbfx.service.system.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MenuServiceImpl implements MenuService {
    @Autowired
    private MenuMapper menuMapper;

    @Override
    public List<Menu> queryAllMenu(Menu menu) {
        return menuMapper.queryAllMenu(menu);
    }

    @Override
    public int checkMenuHasChildren(Integer id) {
        return menuMapper.checkMenuHasChildren(id);
    }

    @Override
    public int deleteMenu(Integer id) {
        if(menuMapper.queryRoleMenu(id) > 0){
            menuMapper.deleteRoleMenu(id);
        }

        return menuMapper.deleteMenu(id);
    }

    @Override
    public String addMenu(Menu menu) {
        if(menuMapper.addMenu(menu) > 0){
            return "节点添加成功";
        }
        return "节点添加失败！";
    }

    @Override
    public String updateMenu(Menu menu) {
        if(menuMapper.updateMenu(menu) > 0){
            return "节点修改成功";
        }
        return "节点修改失败！";
    }
}